use actix_web::{error::ErrorInternalServerError, web, Responder, Result};

use crate::{
    api_get, api_get_in_page, api_get_relevant,
    config::get_page_size,
    database::DbPool,
    route::form::path::{PageForm, SlugForm},
    service::class,
};

pub fn config_api_post(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/post")
            .route("/page/{page}", web::get().to(get_posts))
            .service(
                web::scope("/{slug}")
                    .route("/info", web::get().to(get_post))
                    .route("/view", web::get().to(view_post))
                    .route("/image", web::get().to(get_post_images)),
            ),
    );
}

api_get!(get_post, SlugForm, class::post::get_by_sid);
api_get!(view_post, SlugForm, class::post::view);
api_get_in_page!(get_posts, PageForm, class::post::get_with_author_in_page);
api_get_relevant!(get_post_images, SlugForm, class::image::get_by_post_sid);
